<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT'].'/');
$folderPath = ROOT_DIR .'uploads/canvas/';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405); 
    echo json_encode(['error' => 'Inewed.']);
    exit;
}


$contentType = isset($_SERVER['CONTENT_TYPE']) ? trim($_SERVER['CONTENT_TYPE']) : '';


if (strpos($contentType, 'application/json') !== 0) {
    http_response_code(415); 
    echo json_encode(['error' => 'IEed.']);
    exit;
}


$rawData = file_get_contents('php://input');

$input = json_decode($rawData, true); 

if (json_last_error() !== JSON_ERROR_NONE) {
    http_response_code(400); 
    echo json_encode(['error' => 'E']);
    exit;
}


if (!isset($input['name'])) {
    http_response_code(400); 
    echo json_encode(['error' => 'E']);
    exit;
}

$fileName = $input['name'];
unlink($folderPath . $fileName);
echo json_encode(['message' => '文件已成功删除']);
?>